package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo {
    public static void main(String[] args) {
        /**
         *
         */
        try (
                Connection connection = DBUtill.getConnection()
        ){
            Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.salary,t.title,c.name,c.floor " +
                         "FROM teacher t " +
                         "JOIN class c ON t.id = c.teacher_id " +
                         "WHERE t.name = '王克晶' ";
            System.out.println(sql);
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()){
//                String name = rs.getString("name");
//                int salary = rs.getInt("salary");
//                String title = rs.getString("title");
//                String className = rs.getString("name");
//                int floor = rs.getInt("floor");
                String name = rs.getString(1);
                int salary = rs.getInt(2);
                String title = rs.getString(3);
                String className = rs.getString(4);
                int floor = rs.getInt(5);
                System.out.println(name+" "+salary+" "+title+" "+className+" "+floor);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
